package com.example.beat_x3.Fragments;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.beat_x3.Client.GetResult;
import com.example.beat_x3.R;

import Entity.Inf;

public class ComplaintFragment extends MyFragment {
    EditText complain_text;

    Button complain_button;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_complaint, null);
        complain_text = view.findViewById(R.id.complaint_content);
        complain_button = view.findViewById(R.id.complaint_button);
        complain_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (complain_text.length() != 0) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            if (GetResult.ComplaintGR(Inf.stuInf.StudentAccount, complain_text.getText().toString()) == 1) {
                                if (Inf.feedbackFragment != null) {
                                    Inf.feedbackFragment.feedbackAdapter.res.complaints.add(complain_text.getText().toString());
                                    Inf.feedbackFragment.feedbackAdapter.res.replys.add("");
                                    Inf.feedbackFragment.feedbackAdapter.refreshOne();
                                }
                                Looper.prepare();
                                Toast.makeText(Inf.context, "提交成功", Toast.LENGTH_SHORT).show();
                                Looper.loop();
                            }
                        }
                    }).start();
                }
            }
        });

        view.findViewById(R.id.complaint_backbutton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeFragment(Inf.centerFragment);
            }
        });
        return view;
    }
}
